package com.smart.common.entities.core;

import io.swagger.annotations.ApiModelProperty;
import lombok.Getter;
import lombok.Setter;

import javax.validation.constraints.Max;
import javax.validation.constraints.Min;
import javax.validation.constraints.NotNull;
import java.io.Serializable;

/**
 * @author 夏绪秋
 */

@Getter
@Setter
public class BaseSearch implements Serializable {

    /**
     * 当前页码
     */
    @ApiModelProperty(value = "分页页码", required = true)
    @NotNull(message = "分页参数错误:当前页码不能为空")
    @Min(value = 1, message = "分页参数错误:请求的页码数不能小于1")
    int pageNo;

    /**
     * 每页数据条数
     */
    @ApiModelProperty(value = "分页长度", required = true)
    @NotNull(message = "分页参数错误:分页长度不能为空")
    @Min(value = 1, message = "分页参数错误:分页长度不能小于1")
    @Max(value = 100, message = "分页长度不能超过100条每页")
    int pageSize;


    /**
     * 获取最大行
     *
     * @return int
     */
    public int maxRows() {
        return this.pageSize;
    }

    /**
     * 获取游标行
     *
     * @return int
     */
    public int firstRow() {
        return (this.pageNo - 1) * this.pageSize;
    }

}
